package com.yz.android18_propertyanimator;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private Context mContext = this;
    private ImageView imageView_main;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        imageView_main = (ImageView) findViewById(R.id.imageView_main);
    }

    public void clickView(View view) {
        Animator animator = null;
        switch (view.getId()) {
            case R.id.button_alpha:
                animator = AnimatorInflater.loadAnimator(mContext, R.animator.alpha);
                break;
            case R.id.button_rotate:
                animator = AnimatorInflater.loadAnimator(mContext, R.animator.rotate);
                break;
            case R.id.button_scale:
                animator = AnimatorInflater.loadAnimator(mContext, R.animator.scale);
                break;
            case R.id.button_translate:
                animator = AnimatorInflater.loadAnimator(mContext, R.animator.translate);
                break;
        }
        animator.setTarget(imageView_main);
        animator.start();

    }

    public void clickView_java(View view) {
        Animator animator=null;
        Animator animator_X=null;
        Animator animator_Y=null;
        switch (view.getId()) {
            case R.id.button_alpha_java:
                animator=ObjectAnimator.ofFloat(imageView_main,"alpha",1.0f,0.0f,0.5f,0.0f);
                ((ObjectAnimator)animator).setRepeatCount(ValueAnimator.INFINITE);
                ((ObjectAnimator)animator).setRepeatMode(ValueAnimator.REVERSE);
                ((ObjectAnimator)animator).setDuration(3000);
                animator.start();
                break;
            case R.id.button_rotate_java:
                animator=ObjectAnimator.ofFloat(imageView_main,"rotate",0.0f,250f);
                ((ObjectAnimator)animator).setRepeatCount(ValueAnimator.INFINITE);
                ((ObjectAnimator)animator).setRepeatMode(ValueAnimator.REVERSE);
                ((ObjectAnimator)animator).setDuration(3000);
                animator.start();
                break;
            case R.id.button_scale_java:
                animator_X=ObjectAnimator.ofFloat(imageView_main,"scaleX",0.0f,2f);
                ((ObjectAnimator)animator_X).setRepeatCount(ValueAnimator.INFINITE);
                ((ObjectAnimator)animator_X).setRepeatMode(ValueAnimator.REVERSE);
                ((ObjectAnimator)animator_X).setDuration(3000);
                animator_X.start();
                animator_Y=ObjectAnimator.ofFloat(imageView_main,"scaleY",0.0f,2f);
                ((ObjectAnimator)animator_Y).setRepeatCount(ValueAnimator.INFINITE);
                ((ObjectAnimator)animator_Y).setRepeatMode(ValueAnimator.REVERSE);
                ((ObjectAnimator)animator_Y).setDuration(3000);
                animator_Y.start();

                break;
            case R.id.button_translate_java:
                animator_X=ObjectAnimator.ofFloat(imageView_main,"translateX",0.0f,500f);
                ((ObjectAnimator)animator_X).setRepeatCount(ValueAnimator.INFINITE);
                ((ObjectAnimator)animator_X).setRepeatMode(ValueAnimator.REVERSE);
                ((ObjectAnimator)animator_X).setDuration(3000);
                animator_X.start();
                animator_Y=ObjectAnimator.ofFloat(imageView_main,"translateY",0.0f,300f);
                ((ObjectAnimator)animator_Y).setRepeatCount(ValueAnimator.INFINITE);
                ((ObjectAnimator)animator_Y).setRepeatMode(ValueAnimator.REVERSE);
                ((ObjectAnimator)animator_Y).setDuration(3000);
                animator_Y.start();
                break;
        }
    }
}
